package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> findByUid(Long userId);

    //更新购物车的数量
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    void updateNumberById(ShoppingCart dbCart);

    //插入购物车
    @Insert("insert into shopping_cart values(null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void save(ShoppingCart shoppingCart);

    ShoppingCart findByUidAnds(ShoppingCart shoppingCart);

    //清空购物车
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void removeByUid(Long userId);


    @Select("select * from shopping_cart where dish_id=#{dishId}")
    ShoppingCart findByDishId(Long dishId);

    @Delete("delete from shopping_cart where dish_id=#{dishId}")
    void deleteByDishId(Long dishId);

    @Select("select * from shopping_cart where setmeal_id=#{setmealId}")
    ShoppingCart findBySetmealId(Long setmealId);

    @Delete("delete from shopping_cart where setmeal_id=#{setmealId}")
    void deleteBysetmealId(Long setmealId);
}
